package org.example.ims.Entity.WareHouseProduct;


import lombok.*;
import jakarta.persistence.*;
import org.example.ims.Entity.Base.Warehouse;
import org.example.ims.Entity.Base.Product;

import java.time.LocalDateTime;

/*仓库库存信息*/
@Data
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "WarehouseProduct")
public class WarehouseProduct {
    @EmbeddedId
    private WarehouseProductId id;

    @Column(nullable = false)
    private Integer quantity=0;

    @Column(name = "last_updated", nullable = false)
    private LocalDateTime lastUpdated;

    @ManyToOne
    @MapsId("warehouseId")
    @JoinColumn(name = "warehouse_id")
    private Warehouse warehouse;

    @ManyToOne
    @MapsId("productId")
    @JoinColumn(name = "product_id")
    private Product product;

    @PrePersist
    @PreUpdate
    protected void onSaveOrUpdate() {
        lastUpdated = LocalDateTime.now();
    }
}
